<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="chtml" uri="http://www.szhelper.com/jsp/html"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<chtml:script src="/js/ajaxfileupload.js" />
<title>群发站内信</title>
</head>
<body>
<div class="youarehere">网站内容管理 &gt; <span>管理站内信</span>&gt; <span>群发站内信</span></div>
<div id="layout_documentation" onclick="javascript: closeBar();">
<script type="text/javascript">
 	function valid4message(label, pattern, value, validEle, maskEle, isCheckNull){
		value = value.replace(/(^\s*)|(\s*$)/g, "");
		if(value.length > 0)
		{
			if(new RegExp(pattern).test(value))
			{
				$('#'+validEle+'').hide();
				$('#'+maskEle+'').hide();
				return true;
			}
			else
			{
				$('#'+validEle+'').html("<label>&nbsp;</label>"+label+"格式错误");
				$('#'+validEle+'').show();
				$('#'+maskEle+'').show();
				return false;
			};
		}
		else
		{
			if(isCheckNull == 'true')
			{
				$('#'+validEle+'').html("<label>&nbsp;</label>"+label+"不能为空");
				$('#'+validEle+'').show();
				$('#'+maskEle+'').show();
				return false;
			}
			else
			{
				$('#'+validEle+'').hide();
				$('#'+maskEle+'').hide();
				return true;
			}
		}
	}
	function isNull4message(label, eleName, validEle, maskEle){
		var flag=false;
		var checkvalue = $("input[name='"+eleName+"']");
		checkvalue.each(function()
		{
			if(this.checked==true)
			{
				flag = true;
			}
		});
		if(!flag)
		{
			$('#'+validEle+'').html("<label>&nbsp;</label>"+label+"不能为空");
			$('#'+validEle+'').show();
			$('#'+maskEle+'').show();
			return false;
		}
		else
		{
			$('#'+validEle+'').hide();
			$('#'+maskEle+'').hide();
			return true;
		}
	}
// message数据列表表单提交脚本
function _submitAction4message(obj, action, params)
{
		var submitForm;
		while ((obj.parentNode) && (obj.parentNode.tagName) && (!obj.parentNode.tagName.match(/FORM/i)))
		{
			obj = obj.parentNode;
		}
		submitForm = obj.parentNode;
		if(!submitForm)
		{
			submitForm = document.createElement("form");
			document.body.appendChild(submitForm);
		}
		submitForm.setAttribute("action", action);
		submitForm.setAttribute("method", "POST");
		for(var key in params)
		{
				var hiddenField = document.createElement("input");
				hiddenField.setAttribute("type", "hidden");
				hiddenField.setAttribute("name", key);
				hiddenField.setAttribute("value", params[key]);
				submitForm.appendChild(hiddenField);
		}
if(submit4message()) submitForm.submit();
}

function import_recevicer()
{
	var _file_name = $("#fileToUpload").val();
	if(_file_name == "" || _file_name.trim().length == 0)
	{
		alert("请选择要上传的文本.");
		return;
	}
	var _file_format = _file_name.substring(_file_name.lastIndexOf(".")+1,_file_name.length).toLowerCase();
	if(_file_format!="txt")
	{
		alert("不支持的文本格式.");
		return;
	}
	$.ajaxFileUpload(
		     {
		     url:'<chtml:path path="/" />message/upload',            
		     secureuri:false,
		     fileElementId:'fileToUpload',                     
		     dataType: 'json',                           
		     success: function (data, status)            
		   	 {  
				$("#receiver").val(data);    
		     },
		     error: function (data, status, e)            
		     {
		    	 alert("上传出错!"+e);
		         return;
		     }
		 });
}

</script>
<form id="message"  action="<chtml:path path="/" />message/sendBatch" method="post" onsubmit="return submit4message();">
<table class="data_table_main">
<tr>
<td background="<chtml:path path="/" />layout/list/tab_top.gif">
<!-- message标题头 -->
<table class="data_table_title">
<tr>
<td width="12" height="30"><img src="<chtml:path path="/" />layout/list/tab_left_top.gif" width="12" height="30" /></td><td align='left'><img src="<chtml:path path="/" />layout/list/list.gif" width="16" height="16" />群发</td>
<td align='right'>
&nbsp;
</td><td width="16"><img src="<chtml:path path="/" />layout/list/tab_right_top.gif" width="16" height="30" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="8" background="<chtml:path path="/" />layout/list/tab_left.gif">&nbsp;</td>
<td>
<!-- message数据区 -->
<table id="main_table4message" class="data_table_command">
<tr>
<td class="data_tab_tdr">标题</td>
<td class="data_tab_tdl"><input id="title" type="text" name="title" value="" />&nbsp;<span style="color:red;">*</span><span style="color:gray;font-style: italic;font-size: small;"></span>
<div id="mask4title" style="display: none;"></div>
<div id="valid4title" style="display: none;color: red;font-size: small;"></div>
</td>
</tr>
<tr>
<td class="data_tab_tdr">内容</td>
<td class="data_tab_tdl"><textarea id="content" name="content" ></textarea>&nbsp;<span style="color:red;">*</span><span style="color:gray;font-style: italic;font-size: small;"></span>
<div id="mask4content" style="display: none;"></div>
<div id="valid4content" style="display: none;color: red;font-size: small;"></div>
</td>
</tr>
<tr id="store_tr">
<td class="data_tab_tdr">会员店</td>
<td class="data_tab_tdl">
	<select name="storeId">
		<c:forEach items="${stores}" var="store" varStatus="status">
		 <option value="${store.id}">${store.name}</option>
		</c:forEach>
	</select>
</td>
</tr>
<tr>
<td class="data_tab_tdr">收件人 :</td>
<td class="data_tab_tdl">
	<table border="0">
		<tr>
			<td>选择导入文本：<input type="file" id="fileToUpload" name="fileToUpload" value=""/>&nbsp;&nbsp;<input type="button" onclick="javascript:import_recevicer();" id="importsbt" value="导入"/></td>
		</tr>
		<tr>
			<td><textarea id="receiver" name="receiver" cols="90" rows="5">在输入框中输入收件人的投注卡号，中间用";"隔开，也可以通过.txt格式导入收件人</textarea></td>
		</tr>
	</table>
</td>
</tr>
<tr>
<td colspan="2" align="center" height="25" class="data_tab_td">
<button type="button" onclick="javascript:void(_submitAction4message(this,'<chtml:path path="/" />message/sendBatch',{}));return false;"  />·发布·</button>&nbsp;&nbsp;
<button onclick="javascript:void(history.back(-1));" type=button>·返回·</button>&nbsp;&nbsp;
</td>
</tr>
</table>
</td>
<td width="8" background="<chtml:path path="/" />layout/list/tab_right.gif">&nbsp;</td> </tr>
</table>
</td>
</tr>
<tr>
<td background="<chtml:path path="/" />/layout/list/tab_bottom.gif">
<table class="data_table_pagination" align='center' cellpadding='0' cellspacing='0'>
<tr><td width="12" height="35"><img src="<chtml:path path="/" />layout/list/tab_left_bottom.gif" width="12" height="35" /></td><td>&nbsp;</td><td width="16"><img src="<chtml:path path="/" />layout/list/tab_right_bottom.gif" width="16" height="35" /></td></tr></table>
</td>
</tr>
</table>
<!-- message结束 -->
<input id="id" type="hidden" name="id" value="" />
<input id="version" type="hidden" name="version" value="0" />
</form>
<script type="text/javascript">
 	function submit4message(){
		var validResult = true;
		if(validResult){
			validResult = valid4message('标题','^[\\s\\S]*$',$('#title').val(),'valid4title', 'mask4title', 'true');
		}
		if(validResult){
			validResult = valid4message('内容','^[\\s\\S]*$',$('#content').val(),'valid4content', 'mask4content', 'true');
		}
		if(validResult){
			validResult = sbtcheck();
		}
		return validResult;
	}
 	function sbtcheck()
	{
 		if($("#receiver").val()=="" || $("#receiver").val().trim().length == 0)
		{
				alert("收件人不能为空!");
				return false;
		}
		return true;
	}
	new ResizeWidget('main_table4message');
</script>
</div>
<!--说明   -->	
<div class="sm_info">
	<p class="row_one">说明：</p>
	<p class="other"></p>
	<p class="other"></p>
</div>
</body>
</html>